package com.huawei.hbase.data;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

public class GetData {
    public static void main(String[] args) throws IOException {
        //??hbase
        Configuration conf = HBaseConfiguration.create();
        //???zookeeper??????????zookeeper??
        conf.set("hbase.zookeeper.quorum",
                "xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx");
        conf.set("hbase.zookeeper.property.clientPort", "2181");
        Connection connection = ConnectionFactory.createConnection(conf);

        Table hTable = connection.getTable(TableName.valueOf("users"));

        Get get = new Get(Bytes.toBytes("row1"));
        Result result = hTable.get(get);
        byte[] family = Bytes.toBytes("f");
        byte[] buf = result.getValue(family,Bytes.toBytes("id"));
        System.out.println("id="+Bytes.toString(buf));

        buf = result.getValue(family,Bytes.toBytes("age"));
        System.out.println("age="+Bytes.toInt(buf));

        buf = result.getValue(family,Bytes.toBytes("name"));
        System.out.println("name="+Bytes.toString(buf));

        buf = result.getRow();
        System.out.println("rowkey="+Bytes.toString(buf));
    }
}